<template>
    <el-dialog :close-on-click-modal="false"  width="20%" :title="title" :visible.sync="dialogTableVisible">
      <Tree v-if="dialogTableVisible"  ref="tree" :data="dataList" show-checkbox multiple @on-check-change="loadData"></Tree>
      <span slot="footer" class="dialog-footer">
        <el-button @click="save('0')">取 消</el-button>
        <el-button type="primary" @click="save('1')">确 定</el-button>
      </span>
    </el-dialog>
</template>
<style>
 
</style>

<script>
 
import { savePermission } from '@/api/home_'
import htmixin from '@/mixins/htmixin.js'
export default {
  mixins: [htmixin],
  name: 'tree',
  props:{
  },
  data() {
    return {
      dataList:[],
      title:'角色分配',
      nodes:[],
      dialogTableVisible:false
    }
  }, 
  methods: {
    loadData(v){
       this.nodes = v
    },
    save(v){
      if(v=='0'){
        this.dialogTableVisible = false
      }else{
        let selectNode = this.$refs.tree.getCheckedNodes()
        if(selectNode.length==0){
          this.$message.error('请先勾选角色')
        }else{
          let ids = []
          selectNode.forEach((item,index)=>{
            ids.push(item.roleId)
          })
          this.$emit('editSaveUser',JSON.stringify(ids))
        }
      }
    },
    close(){
      this.dialogTableVisible = false
    },
    show(v){
      this.dataList = JSON.parse(v)
      this.dialogTableVisible = true
    }
  },
}
</script>
